package com.qian.fmall.product.impl;

import com.qian.fmall.commons.ResultSet;
import com.qian.fmall.mapper.CategoryMapper;
import com.qian.fmall.mapper.ProductMapper;
import com.qian.fmall.mapper.ProductSkuMapper;
import com.qian.fmall.pojo.Category;
import com.qian.fmall.pojo.Product;
import com.qian.fmall.pojo.ProductSku;
import com.qian.fmall.product.service.ProductService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@DubboService
public class ProductServiceImpl implements ProductService {
    @Resource
    private ProductMapper productMapper;
    @Resource
    private CategoryMapper categoryMapper;
    @Resource
    private ProductSkuMapper productSkuMapper;
    @Override
    public ResultSet getNewProducts() {
        return ResultSet.ok("success",productMapper.getNewProduct());
    }
    @Override
    public ResultSet findCategory() {
        List<Category> allCategory = categoryMapper.getAllCategory(0);
        return ResultSet.ok("success",allCategory);
    }

    @Override
    public List<Category> getCategoryMenu() {
        List<Category> categoryList = categoryMapper.findCategoryProduct(1);
        for (Category category : categoryList) {
            category.setProductList(productMapper.getProductToCategoryId(category.getCategoryLevel()));
        };
        return categoryList;
    }

    @Override
    public Product findProductByProductId(String productId) {
        return productMapper.getProductByProductId(productId);
    }

    @Override
    public List<ProductSku> findProductSkuByProductId(String productId) {
        return productSkuMapper.getProductSkuByProductId(productId);
    }
}
